package com.lanou.zakerproject.subscribe;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.lanou.zakerproject.R;
import com.lanou.zakerproject.base.BaseActivity;
import com.lanou.zakerproject.base.VolleySingleton;
import com.lanou.zakerproject.community.FindAdapter;
import com.lanou.zakerproject.community.TypeData;
import com.lanou.zakerproject.tool.GsonRequest;
import com.lanou3g.greendaodemo.entity.greendao.DaoSingleton;
import com.lanou3g.greendaodemo.entity.greendao.GridViewEntity;
import com.lanou3g.greendaodemo.entity.greendao.GridViewEntityDao;
import com.lanou3g.greendaodemo.entity.greendao.NewsScrollEntity;
import com.lanou3g.greendaodemo.entity.greendao.NewsScrollEntityDao;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 16/1/15.
 */
public class SearchActivity extends BaseActivity implements View.OnClickListener, AdapterView.OnItemClickListener {
    private ListView listView;
    private SearchAdapter searchAdapter;
    private ImageView img_back;
    private String url = "http://iphone.myzaker.com/zaker/block_topic.php?_appid=AndroidPhone&_bsize=1080_1920&_dev=97&_lat=4.9E-324&_lng=4.9E-324&_mac=08%3A00%3A27%3A3f%3A7a%3A01&_mcode=B51557E3&_net=wifi&_nudid=7891a15eb7d34771&_os=5.1_GoogleNexus5-5.1.0-API22-1080x1920&_os_name=GoogleNexus5-5.1.0-API22-1080x1920&_udid=5.1_GoogleNexus5-5.1.0-API22-1080x1920.08%3A00%3A27%3A3f%3A7a%3A01&_v=6.4.5&_version=6.44&id=54dee8fa9490cbde430000ba";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_find);
        listView = (ListView) findViewById(R.id.find_channel_lisview);
        img_back = (ImageView) findViewById(R.id.action_find_back);
        getRequsetData(url);
        img_back.setOnClickListener(this);
        listView.setOnItemClickListener(this);
    }

    @Override
    public void onClick(View v) {
        finish();
    }

    /**
     * 解析数据的方法
     *
     * @param urls 接口
     */
    private void getRequsetData(String urls) {
        GsonRequest<ChannelSearch> gsonRequest = new GsonRequest<>(urls, ChannelSearch.class, new Response.Listener<ChannelSearch>() {
            @Override
            public void onResponse(ChannelSearch response) {
                searchAdapter = new SearchAdapter(SearchActivity.this, response);
                listView.setAdapter(searchAdapter);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
            }
        });
        VolleySingleton.getInstance()._addRequest(gsonRequest);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        toast("相同的，不写了……没用");
    }
}
